<template>
  <el-dialog
     v-drag
    :title="!dataForm.storeId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="上级门店ID" prop="parentId">
      <el-input size="mini"  v-model="dataForm.parentId" placeholder="上级门店ID" clearable></el-input>
    </el-form-item>
    <el-form-item label="门店编码" prop="storeCode">
      <el-input size="mini"  v-model="dataForm.storeCode" placeholder="门店编码" clearable></el-input>
    </el-form-item>
    <el-form-item label="批发商Id" prop="companyId">
      <el-input size="mini"  v-model="dataForm.companyId" placeholder="批发商Id" clearable></el-input>
    </el-form-item>
    <el-form-item label="批发商编码" prop="companyCode">
      <el-input size="mini"  v-model="dataForm.companyCode" placeholder="批发商编码" clearable></el-input>
    </el-form-item>
    <el-form-item label="批发商名称" prop="companyName">
      <el-input size="mini"  v-model="dataForm.companyName" placeholder="批发商名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="门店类别 0:单体，1:连锁" prop="storeType">
      <el-input size="mini"  v-model="dataForm.storeType" placeholder="门店类别 0:单体，1:连锁" clearable></el-input>
    </el-form-item>
    <el-form-item label="门店名称" prop="storeName">
      <el-input size="mini"  v-model="dataForm.storeName" placeholder="门店名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="支付宝账号" prop="alipayAppId">
      <el-input size="mini"  v-model="dataForm.alipayAppId" placeholder="支付宝账号" clearable></el-input>
    </el-form-item>
    <el-form-item label="微信账号" prop="wxAppId">
      <el-input size="mini"  v-model="dataForm.wxAppId" placeholder="微信账号" clearable></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="contactor">
      <el-input size="mini"  v-model="dataForm.contactor" placeholder="联系人" clearable></el-input>
    </el-form-item>
    <el-form-item label="电话/(客服电话)" prop="tel">
      <el-input size="mini"  v-model="dataForm.tel" placeholder="电话/(客服电话)" clearable></el-input>
    </el-form-item>
    <el-form-item label="手机" prop="mobile">
      <el-input size="mini"  v-model="dataForm.mobile" placeholder="手机" clearable></el-input>
    </el-form-item>
    <el-form-item label="省代码" prop="proviceCode">
      <el-input size="mini"  v-model="dataForm.proviceCode" placeholder="省代码" clearable></el-input>
    </el-form-item>
    <el-form-item label="省名称" prop="proviceName">
      <el-input size="mini"  v-model="dataForm.proviceName" placeholder="省名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="市代码" prop="cityCode">
      <el-input size="mini"  v-model="dataForm.cityCode" placeholder="市代码" clearable></el-input>
    </el-form-item>
    <el-form-item label="市名称" prop="cityName">
      <el-input size="mini"  v-model="dataForm.cityName" placeholder="市名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="区代码" prop="zoneCode">
      <el-input size="mini"  v-model="dataForm.zoneCode" placeholder="区代码" clearable></el-input>
    </el-form-item>
    <el-form-item label="区名称" prop="zoneName">
      <el-input size="mini"  v-model="dataForm.zoneName" placeholder="区名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="营业地址" prop="storeAddress">
      <el-input size="mini"  v-model="dataForm.storeAddress" placeholder="营业地址" clearable></el-input>
    </el-form-item>
    <el-form-item label="门店logo" prop="storeLogo">
      <el-input size="mini"  v-model="dataForm.storeLogo" placeholder="门店logo" clearable></el-input>
    </el-form-item>
    <el-form-item label="门店视频" prop="storeVideo">
      <el-input size="mini"  v-model="dataForm.storeVideo" placeholder="门店视频" clearable></el-input>
    </el-form-item>
    <el-form-item label="营业时间" prop="shopTime">
      <el-input size="mini"  v-model="dataForm.shopTime" placeholder="营业时间" clearable></el-input>
    </el-form-item>
    <el-form-item label="证件号码" prop="certNumber">
      <el-input size="mini"  v-model="dataForm.certNumber" placeholder="证件号码" clearable></el-input>
    </el-form-item>
    <el-form-item label="证件图片" prop="certPic">
      <el-input size="mini"  v-model="dataForm.certPic" placeholder="证件图片" clearable></el-input>
    </el-form-item>
    <el-form-item label="门店描述" prop="storeDescription">
      <el-input size="mini"  v-model="dataForm.storeDescription" placeholder="门店描述" clearable></el-input>
    </el-form-item>
    <el-form-item label="经度" prop="longitude">
      <el-input size="mini"  v-model="dataForm.longitude" placeholder="经度" clearable></el-input>
    </el-form-item>
    <el-form-item label="纬度" prop="latitude">
      <el-input size="mini"  v-model="dataForm.latitude" placeholder="纬度" clearable></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input size="mini"  v-model="dataForm.createTime" placeholder="创建时间" clearable></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      <el-input size="mini"  v-model="dataForm.updateTime" placeholder="修改时间" clearable></el-input>
    </el-form-item>
    <el-form-item label="创建人" prop="createUsername">
      <el-input size="mini"  v-model="dataForm.createUsername" placeholder="创建人" clearable></el-input>
    </el-form-item>
    <el-form-item label="创建人id" prop="createUserId">
      <el-input size="mini"  v-model="dataForm.createUserId" placeholder="创建人id" clearable></el-input>
    </el-form-item>
    <el-form-item label="修改人" prop="updateUsername">
      <el-input size="mini"  v-model="dataForm.updateUsername" placeholder="修改人" clearable></el-input>
    </el-form-item>
    <el-form-item label="修改人id" prop="updateUserId">
      <el-input size="mini"  v-model="dataForm.updateUserId" placeholder="修改人id" clearable></el-input>
    </el-form-item>
    <el-form-item label="是否可用 1:是" prop="status">
      <el-input size="mini"  v-model="dataForm.status" placeholder="是否可用 1:是" clearable></el-input>
    </el-form-item>
    <el-form-item label="是否删除 1:是" prop="isDeleted">
      <el-input size="mini"  v-model="dataForm.isDeleted" placeholder="是否删除 1:是" clearable></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input size="mini"  v-model="dataForm.remark" placeholder="备注" clearable></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          storeId: 0,
          parentId: '',
          storeCode: '',
          companyId: '',
          companyCode: '',
          companyName: '',
          storeType: '',
          storeName: '',
          alipayAppId: '',
          wxAppId: '',
          contactor: '',
          tel: '',
          mobile: '',
          proviceCode: '',
          proviceName: '',
          cityCode: '',
          cityName: '',
          zoneCode: '',
          zoneName: '',
          storeAddress: '',
          storeLogo: '',
          storeVideo: '',
          shopTime: '',
          certNumber: '',
          certPic: '',
          storeDescription: '',
          longitude: '',
          latitude: '',
          createTime: '',
          updateTime: '',
          createUsername: '',
          createUserId: '',
          updateUsername: '',
          updateUserId: '',
          status: '',
          isDeleted: '',
          remark: ''
        },
        dataRule: {
          parentId: [
            { required: true, message: '上级门店ID不能为空', trigger: 'blur' }
          ],
          storeCode: [
            { required: true, message: '门店编码不能为空', trigger: 'blur' }
          ],
          companyId: [
            { required: true, message: '批发商Id不能为空', trigger: 'blur' }
          ],
          companyCode: [
            { required: true, message: '批发商编码不能为空', trigger: 'blur' }
          ],
          companyName: [
            { required: true, message: '批发商名称不能为空', trigger: 'blur' }
          ],
          storeType: [
            { required: true, message: '门店类别 0:单体，1:连锁不能为空', trigger: 'blur' }
          ],
          storeName: [
            { required: true, message: '门店名称不能为空', trigger: 'blur' }
          ],
          alipayAppId: [
            { required: true, message: '支付宝账号不能为空', trigger: 'blur' }
          ],
          wxAppId: [
            { required: true, message: '微信账号不能为空', trigger: 'blur' }
          ],
          contactor: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          tel: [
            { required: true, message: '电话/(客服电话)不能为空', trigger: 'blur' }
          ],
          mobile: [
            { required: true, message: '手机不能为空', trigger: 'blur' }
          ],
          proviceCode: [
            { required: true, message: '省代码不能为空', trigger: 'blur' }
          ],
          proviceName: [
            { required: true, message: '省名称不能为空', trigger: 'blur' }
          ],
          cityCode: [
            { required: true, message: '市代码不能为空', trigger: 'blur' }
          ],
          cityName: [
            { required: true, message: '市名称不能为空', trigger: 'blur' }
          ],
          zoneCode: [
            { required: true, message: '区代码不能为空', trigger: 'blur' }
          ],
          zoneName: [
            { required: true, message: '区名称不能为空', trigger: 'blur' }
          ],
          storeAddress: [
            { required: true, message: '营业地址不能为空', trigger: 'blur' }
          ],
          storeLogo: [
            { required: true, message: '门店logo不能为空', trigger: 'blur' }
          ],
          storeVideo: [
            { required: true, message: '门店视频不能为空', trigger: 'blur' }
          ],
          shopTime: [
            { required: true, message: '营业时间不能为空', trigger: 'blur' }
          ],
          certNumber: [
            { required: true, message: '证件号码不能为空', trigger: 'blur' }
          ],
          certPic: [
            { required: true, message: '证件图片不能为空', trigger: 'blur' }
          ],
          storeDescription: [
            { required: true, message: '门店描述不能为空', trigger: 'blur' }
          ],
          longitude: [
            { required: true, message: '经度不能为空', trigger: 'blur' }
          ],
          latitude: [
            { required: true, message: '纬度不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          createUsername: [
            { required: true, message: '创建人不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '创建人id不能为空', trigger: 'blur' }
          ],
          updateUsername: [
            { required: true, message: '修改人不能为空', trigger: 'blur' }
          ],
          updateUserId: [
            { required: true, message: '修改人id不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '是否可用 1:是不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除 1:是不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.storeId = id || 0
        this.visible = true
        this.$nextTick(async () => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.storeId) {
            const res = await this.$http({
              url: `/store/storeinfo/info/${this.dataForm.storeId}`,
              method: 'get',
              params: this.$http.adornParams()
            })
                let data = res.data
                if (data && data.code === 0) {
                    this.dataForm = data.storeInfo
                }
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate(async (valid) => {
          if (valid) {
            const res = await this.$http({
              url:`/store/storeinfo/${!this.dataForm.storeId ? 'save' : 'update'}`,
              method: 'post',
             data: this.$http.adornData( this.dataForm)
            })
            let data = res.data
            if (data && data.code === 0) {
                this.$message({
                        message: '操作成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                }
            })
            } else {
                this.$message.error(data.msg)
            }
          }
        })
      }
    }
  }
</script>
